//
//  nextTableViewCell.m
//  ProJectB_1
//
//  Created by lanou3g on 16/8/26.
//  Copyright © 2016年 yangshukai. All rights reserved.
//

#import "nextTableViewCell.h"
#import "AppDelegate.h"

@implementation nextTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        _mySwitch = [[UISwitch alloc]initWithFrame:CGRectMake(self.frame.size.width, 5, 20, self.frame.size.height - 10)];
        _mySwitch.tag = 1001;
        [_mySwitch addTarget:self action:@selector(changeAction:) forControlEvents:(UIControlEventValueChanged)];
        _label = [[UILabel alloc]initWithFrame:CGRectMake(20, 0, 50, self.frame.size.height)];
        AppDelegate *app = (AppDelegate*)[[UIApplication sharedApplication]delegate];
        if (!app.yeJianisOn) {
            _label.text = @"关";
        }else{
            _label.text = @"开";
        }
        
        _mySwitch.on = app.yeJianisOn;
        [self.contentView addSubview:_mySwitch];

        [self.contentView addSubview:_label];
    }
    return self;
}

- (void)changeAction:(id)sender{
    AppDelegate *app = (AppDelegate*)[[UIApplication sharedApplication]delegate];
    if (_mySwitch.isOn) {
        _label.text = @"开";
        if (app.yeJianView == nil) {
            app.yeJianView = [[UIView alloc]initWithFrame:[UIScreen mainScreen].bounds];
            app.yeJianView.backgroundColor = [UIColor blackColor];
            app.yeJianView.alpha = 0.5;
            app.yeJianView.userInteractionEnabled = NO;
        }
        [[[UIApplication sharedApplication] delegate].window addSubview:app.yeJianView];
    }else{
        _label.text = @"关";
        if (app.yeJianView != nil) {
            [((AppDelegate *)[[UIApplication sharedApplication] delegate]).yeJianView removeFromSuperview];
            ((AppDelegate *)[[UIApplication sharedApplication] delegate]).yeJianView = nil;
        }
    }
    app.yeJianisOn = _mySwitch.isOn;
}



- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

@end
